package com.hulman.oms.web;

import com.hulman.oms.bean.SemiReport;
import com.hulman.oms.bean.Result;
import com.hulman.oms.bean.SemiReport;
import com.hulman.oms.service.SemiReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: maxwellens
 */
@RestController
public class SemiReportController
{
	@Autowired
	private SemiReportService semiReportService;

	@GetMapping("/semi-reports/{id}")
	public Result findSemiReportById(@PathVariable Integer id)
	{
		SemiReport semiReport = semiReportService.findSemiReportById(id);
		return new Result(semiReport);
	}

	@GetMapping("/semi-reports")
	public Result findSemiReports(Integer page, Integer limit, Integer year, Integer semi, Integer createById, String createByName, Integer state)
	{
		Map<String, Object> map = new HashMap<>();
		map.put("page", page);
		map.put("limit", limit);
        map.put("year", year);
        map.put("semi", semi);
        map.put("createById", createById);
        map.put("createByName", createByName);
        map.put("state", state);
		return semiReportService.findSemiReportsResult(map);
	}

	@DeleteMapping("/semi-reports/{id}")
	public Result deleteSemiReportById(@PathVariable Integer id)
	{
		semiReportService.deleteSemiReportById(id);
		return Result.SUCCESS;
	}

	@PutMapping("/semi-reports")
	public Result saveSemiReport(SemiReport semiReport)
	{
		semiReportService.saveSemiReport(semiReport);
		return Result.SUCCESS;
	}
	@PostMapping("/semi-reports/create")
	public Result create(SemiReport semiReport) throws IOException
	{
		semiReportService.create(semiReport);
		return Result.SUCCESS;
	}

	@PostMapping("/semi-reports/submit")
	public Result submit(Integer id) throws IOException
	{
		semiReportService.submit(id);
		return Result.SUCCESS;
	}
}
